
var class_num=location.search;
class_num=class_num.split('?')[1];
hui.loading('加载中',false);
$('#href_list').attr('href','details_stu.html?'+class_num);
$('#href_course').attr('href','details_course.html?'+class_num);
if (islogin()) {
    $.post({
        url:"../requests/select_class_name.php",
        data:{'class_num':class_num},
        success:function (data) {
            if (data != 'none') {
                $('h1').append(data);
            }
        }
    });
    $.post({
        url:'../requests/select_progress.php',
        data:{'class_num':class_num},
        async:false,
        success:function (data) {
            hui('#course_progress').progressBar(data*100);
            $('.progress_text').text(data*100+'%');
        }
    });
    $.post({
        url:'../requests/select_sec_sub.php',
        data:{'class_num':class_num},
        async:false,
        success:function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].taken==1) {
                    var dom1="<div class='course'><h2>\n" +
                        "                <span class='hui-primary-txt'>第"+data[i].num+"章</span>&nbsp;<span>"+data[i].name+"</span>\n" +
                        "                <span class=\"hui-more\"><input type=\"radio\" value='sec_"+data[i].num+"' name=\"select\"></span>\n" +
                        "            </h2>" ;
                }
                else {
                    var dom1 = "<div class='course'><h2>\n" +
                        "                <span>第" + data[i].num + "章</span>&nbsp;<span>" + data[i].name + "</span>\n" +
                        "                <span class=\"hui-more\"><input type=\"radio\" value='sec_"+data[i].num+"' name=\"select\"></span>\n" +
                        "            </h2>";
                }
                if (typeof (data[i].sub) != 'undefined') {
                    for (var j=0;j<data[i].sub.length;j++){
                        if (data[i].sub[j].taken ==1) {
                            var dom1=dom1+" <p class=\"sub_box\">\n" +
                                "                <span class='hui-primary-txt'>第"+data[i].sub[j].num+"节</span>&nbsp;<span>"+data[i].sub[j].name+"</span>\n" +
                                "                <span class=\"hui-more\"><input type=\"radio\" value='sec_"+data[i].num+"_sub_"+data[i].sub[j].num+"' name=\"select\"></span>\n" +
                                "            </p>";
                        }
                        else {
                            var dom1 = dom1 + " <p class=\"sub_box\">\n" +
                                "                <span>第" + data[i].sub[j].num + "节</span>&nbsp;<span>" + data[i].sub[j].name + "</span>\n" +
                                "                <span class=\"hui-more\"><input type=\"radio\"value='sec_"+data[i].num+"_sub_"+data[i].sub[j].num+"' name=\"select\"></span>\n" +
                                "            </p>";
                        }
                    }
                    $('.course_box').append(dom1+"</div>");
                }
                else $('.course_box').append(dom1+"</div>");
                hui.closeLoading();
            }
        }
    });
}
hui('#op').click(function(){
    var type;
    var sec_num;
    var sub_num;
    var str=$("input[name='select']:checked").val();
    if (typeof (str)!='undefined') {
        var strs=str.split('_');
        if (strs.length==4){
            type='sub';
            sub_num=strs[3];
            sec_num=strs[1];
        }
        else {
            type='sec';
            sec_num=strs[1]
        }
    }
    meuns=['编辑','删除','更改状态','添加'];
    hui.actionSheet(meuns,cancel,function (e) {
        if (e.index == 0) {
            window.location.href='edit_section.html?';
        }
        if (e.index == 1) {
            if (typeof (str) != 'undefined') {
                    hui.confirm('确认删除?如果选择章节将删除该章节所有小节',['取消','确定'],function() {
                        $.post({
                            url:'../requests/delete_sec_sub.php',
                            data:{'type': type, 'class_num': class_num, 'sub_num': sub_num, 'sec_num': sec_num},
                            async:false,
                            success:function (data) {
                                if (data == 1) {
                                    hui.iconToast('删除成功','success');
                                }
                            }
                        });
                    });
                }
            else hui.iconToast('未选择','warn');
        }
        if (e.index == 2) {
            if (typeof (str) != 'undefined') {
                $.post({
                    url: '../requests/change_taken.php',
                    data: {'type': type, 'class_num': class_num, 'sub_num': sub_num, 'sec_num': sec_num},
                    async: false,
                    success: function (data) {
                        if (data == 1) {
                            hui.iconToast('更改成功','success');
                            window.location.href='details_course.html?'+class_num;
                        }
                    }
                });
            }
            else hui.iconToast('未选择','warn');
        }
    });
    meuns=['个人中心','班级','文件','消息'];
});
